<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">

</head>
<style>
    body {
        background: #fafafa;
        background-attachment: fixed !important;
        background-size: cover !important;
    }
</style>
<body>
<!--导航-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui top fixed menu">
    <!--流动导航组件-->
    <div class="m-container">
        <div class="ui secondary stackable menu">
            <div class="item">
                <h2 class="ui header">Ended</h2>
            </div>&nbsp;

            <div class="ui dropdown item m-item m-mobile-hide" th:classappend="${n==1} ? 'active'">
                <div class="text">
                    <i class="anchor icon"></i>博客管理
                </div>
                <div class="menu">
                    <a href="#" th:href="@{/admin/blogs}" class="item">博客列表</a>
                    <a href="#" th:href="@{/admin/blogs/input}" class="item">博客发布</a>
                </div>
            </div>
            <div class="ui dropdown item m-item m-mobile-hide" th:classappend="${n==2} ? 'active'">
                <div class="text">
                    <i class="idea icon"></i>分类管理
                </div>
                <div class="menu">
                    <a href="#" th:href="@{/admin/types}" class="item">分类列表</a>
                    <a href="#" th:href="@{/admin/types/input}" class="item">新增分类</a>
                </div>
            </div>
            <div class="ui dropdown item m-item m-mobile-hide" th:classappend="${n==3} ? 'active'">
                <div class="text">
                    <i class="idea icon"></i>标签管理
                </div>
                <div class="menu">
                    <a href="#" th:href="@{/admin/types}" class="item">标签列表</a>
                    <a href="#" th:href="@{/admin/types/input}" class="item">新增标签</a>
                </div>
            </div>
            <a href="#" th:href="@{/admin/message}" class="m-item item m-mobile-hide" th:classappend="${n==4} ? 'active'">
                <i class="comment alternate icon"></i>留言管理</a>
            <a href="#" th:href="@{/admin/about}" class="m-item item m-mobile-hide" th:classappend="${n==5} ? 'active'">
                <i class="info icon"></i>博主信息</a>
            <div class="m-item item m-mobile-hide">
                <a class="ui basic vertical animated circular button" href="#" target="_blank" th:href="@{/admin/logout}"
                   tabindex="0">
                    <div class="hidden content">注销</div>
                    <div class="visible content">
                        <i class="cloud icon"></i>
                    </div>
                </a>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle basic icon button m-top-right m-mobile-show m-bg">
        <i class="sidebar icon"></i>
    </a>
</nav>


<!--中间内容-->
<div class="m-padded-tb-max m-container-small">
    <div class="ui container">
        <div class="ui segment form">
            <input type="hidden" name="page">
            <div class="inline fields">
                <!--标题-->
                <div class="four wide field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <!--分类-->
                <div class="six wide field">
                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1"
                                     th:data-value="${type.id}" th:text="${type.name}"></div>
                            </div>
                        </div>
                        <button id="clear-btn" class="ui clear small icon button"><i class="close icon"></i></button>
                    </div>
                </div>
                <!--推荐-->
                <div class="two wide field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <!--搜索-->
                <div class="two wide field">
                    <button type="button" id="search-btn" class="ui mini blue basic button">
                        <i class="search icon"></i>搜索
                    </button>
                </div>
                <!--新增-->
                <div class="two wide field">
                    <a href="#" th:href="@{/admin/blogs/input}" class="ui mini right floated blue basic button">
                        <i class="plus icon"></i>新增</a>
                </div>
            </div>
        </div>
        <div id="table-container">
            <!--表内容-->
            <table th:fragment="blogList" class="ui celled table">
                <!--表头-->
                <thead>
                <tr class="center aligned">
                    <th></th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>置顶</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <!--中间内容-->
                <tbody>
                <tr th:each="blog,iterStat : ${page.content}" class="center aligned">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">旅行日记（一）</td>
                    <td th:text="${blog.type.name}">旅游日记</td>
                    <td th:text="${blog.sticky}? '是' : '否'">是</td>
                    <td th:text="${blog.recommend} ? '是' : '否'">是</td>
                    <td th:text="${blog.published} ? '发布':'草稿'">草稿</td>
                    <td th:text="${blog.updateTime}">2020-2-10</td>
                    <td>
                        <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}"
                           class="ui mini blue basic button">编辑</a>
                        <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}"
                           class="ui mini orange basic button">删除</a>
                    </td>
                </tr>
                </tbody>
                <!--footer分页-->
                <tfoot>
                <tr>
                    <th colspan="8">
                        <div class="ui middle aligned two column grid" th:if="${page.totalPages}>1">
                            <div class="center aligned column">
                                <a onclick="page(this)" th:attr="data-page=${page.number}-1"
                                   class="ui compact labeled icon button" th:unless="${page.first}">
                                    <i class="left chevron icon"></i> LAST</a>
                            </div>
                            <div class="center aligned column">
                                <a onclick="page(this)" th:attr="data-page=${page.number}+1"
                                   class="ui compact right labeled icon button" th:unless="${page.last}">
                                    <i class="right chevron icon"></i>NEXT</a>
                            </div>
                        </div>
                    </th>
                </tr>
                </tfoot>
            </table>
            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${message}">恭喜，操作成功！</p>
            </div>
        </div>
    </div>
</div>

<!--底部footer-->
<footer th:replace="admin/_fragments :: footer" class="ui m-bg segment m-padded-tb-huge">
    <div class="ui center aligned container">
        <!--布局会分成16份-->
        <div class="ui divided stackable grid">
            <div class="four wide column">
                <img src="../../static/images/plug/WeChat.PNG" alt="WeChatQR Code" class="ui centered rounded image"
                     style="width: 110px">
            </div>
            <div class="four wide column">
                <h4 class="ui header m-opacity-small">博客简介</h4>
                <p class="m-text-thin m-text-spaced m-opacity-small">
                    创建此博客是为了提供一个平台来供自己分享生活、自己的所见所闻所感、以及分享学习心得和资源......
                </p>
            </div>
            <div class="four wide column">
                <h4 class="ui header m-opacity-small">联系我</h4>
                <div class="ui link list ">
                    <a href="#" class="item">QQ：3320014521</a>
                    <a href="#" class="item">e-mail：woshihauhuaa@outlook.com</a>
                </div>
            </div>
            <div class="four wide column">
                <div class="three wide column">
                    <br>
                    <br>
                    <p class="m-text-thin m-text-spaced">
                        愿你编码半生，归来仍是少年......
                    </p>
                </div>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-opacity-mini">Copyright © 2020-2021 YanYunHua Designed by YanYunHua</p>
    </div>
</footer>


<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<!--/*/</th:block>/*/-->

<!--导航的手机端按钮的响应页面-->
<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide')
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });
    //消息提示关闭初始化
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade');
        });

    $('#clear-btn')
        .on('click', function () {
            $('.ui.type.dropdown')
                .dropdown('clear')
            ;
        });
    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loaddata();
    }

    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loaddata();
    });

    //使用该object请求方法发送请求，加载数据，实现动态获取表格数据
    function loaddata() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
            title: $("[name='title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val()
        });
    }
</script>

</body>
</html>